package com.timoon.sample.web.user;


import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.googlecode.wicket.jquery.ui.Options;
import com.timoon.app.utils.Constantor;
import com.timoon.app.utils.HttpServletUtil;
import com.timoon.component.panel.jqgrid.JqGridPanel;
import com.timoon.component.panel.jqgrid.JqGridService;
import com.timoon.component.panel.jqgrid.panel.CreatorPanel;
import com.timoon.component.panel.jqgrid.panel.DefaultSearchPanel;
import com.timoon.component.panel.jqgrid.panel.DetailsPanel;
import com.timoon.component.panel.nav.ResourceMapper;
import com.timoon.sample.web.user.panel.UserCreatorPanel;
import com.timoon.sample.web.user.panel.UserDetailsPanel;
import com.timoon.sample.web.user.panel.UserSearchPanel;


public class UserManagerPanel extends Panel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7826928350264942042L;

	@SpringBean(name="com.flt.sample.user.JqGridServiceImpl")
	private JqGridServiceImpl jqGridServiceImpl;
	
	private JqGridPanel grid;
	
	public UserManagerPanel(String id) {
		super(id);
		// TODO Auto-generated constructor stub
		Options ops=new Options();
		ops.set("colModel", "[" +
				"{name:'id',index:'id',label:'ID'}," +
				"{name:'name',index:'name',label:'名字'}," +
				"{name:'phone',index:'phone',label:'电话'}," +
				"{name:'email',index:'email',label:'邮箱'}," +
				"{name:'account',index:'account',label:'用户名'}" +
				"]");
		grid=new JqGridPanel("wk_user", ops, this.jqGridServiceImpl,null){
			private static final long serialVersionUID = 6132568186675562517L;
			
			@Override
			public CreatorPanel getCreatorPanel(String id,JqGridPanel mainPanel,String recordId) {
				// TODO Auto-generated method stub
				return new UserCreatorPanel(id,mainPanel,recordId);
			}
			@Override
			protected DefaultSearchPanel getSearchPanel(String id,JqGridPanel mainPanel) {
				// TODO Auto-generated method stub
				return new UserSearchPanel(id, mainPanel);
			}
			@Override
			public DetailsPanel getDetailsPanel(String id, JqGridPanel mainPanel,String recordId) {
				// TODO Auto-generated method stub
				return new UserDetailsPanel(id, mainPanel,recordId);
			}
			@Override
			public String getPostParamInputs() {
				// TODO Auto-generated method stub
				return ".input-name";
			}
			@Override
			public boolean isButtonVisible(String buttonName) {
				// TODO Auto-generated method stub
				ResourceMapper mapper=(ResourceMapper) this.getSession().getAttribute(Constantor.SESSION_USER_MAPPER);
				boolean visible=false;
				if(buttonName.equals(JqGridPanel.ADD_BUTTON_ENABEL)){
					return mapper.getResourceMap().containsKey("user_add");
				}else if(buttonName.equals(JqGridPanel.DELETE_BUTTON_ENABLE)){
					return mapper.getResourceMap().containsKey("user_delete");
				}else if(buttonName.equals(JqGridPanel.MODIFIER_BUTTON_ENABLE)){
					return mapper.getResourceMap().containsKey("user_modifier");
				}else if(buttonName.equals(JqGridPanel.DETAIL_BUTTON_ENABLE)){
					return mapper.getResourceMap().containsKey("user_details");
				}
				
				return visible;
			}
		};
		add(grid);
	}
	

	public JqGridService getJqGridServiceImpl() {
		return jqGridServiceImpl;
	}

	public void setJqGridServiceImpl(JqGridServiceImpl jqGridServiceImpl) {
		this.jqGridServiceImpl = jqGridServiceImpl;
	}

}
